package day03;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoRequest extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//在redirect后面加上name=**,跳到这里打印出req里面的参数时，会发现名字为空（因为重定向丢失了参数）
//		System.out.println(req);
//		String name=req.getParameter("name");
//		System.out.println(name);
		

	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String name=req.getParameter("name");
		System.out.println(name);
		//中的utf-8字节码  %E4%B8%AD
		//先将字节转回成乱码的字符串
//		System.out.println(name);
//		byte[] bytes= {(byte) 0xE4,(byte) 0xB8,(byte) 0xAD};
//		String s=new String(bytes,"iso-8859-1");
//		System.out.println(s);
		//在将字符串变为原始的字节
//		byte[] bytes2=name.getBytes("iso-8859-1");
//		for(byte b:bytes2) {
//			System.out.print(b+"\t");
//		}
		
		//在将字节变成utf-8编码的字符串
//		String s2=new String(bytes2,"utf-8");
//		System.out.println(s2);
	}
}
